﻿package com.tudou.home.newskin.containers
{
    import com.tudou.home.common.button.*;
    import com.tudou.home.common.net.*;
    import com.tudou.home.common.utils.*;
    import com.tudou.home.newskin.buttons.*;
    import com.tudou.home.newskin.consts.*;
    import com.tudou.home.newskin.events.*;
    import com.tudou.home.newskin.model.*;
    import com.tudou.js.*;
    import com.tudou.net.*;
    import com.tudou.skin.*;
    import com.tudou.track.*;
    import com.tudou.utils.*;
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;
    import flash.text.*;

    public class ShareSprite extends Sprite implements IShare, IInitVideo
    {
        private var shareListSprite:Sprite;
        private var title:HrefIconText;
        private var more:InteractiveObject;
        private var frame1:PhotoFrame;
        private var shareListData:Array;
        private var shareList:Array;
        private var replay:SimpleButton;
        private var baseVideoInfo:IBaseVideoInfo;
        private var shareTitle:TextField;
        private static const LEFT_RIGHT_BETWEEN:uint = 10;

        public function ShareSprite()
        {
            var _loc_1:* = NewSkinConsts.SHARE_WIDTH;
            var _loc_2:* = NewSkinConsts.SHARE_HEIGHT;
            var _loc_3:* = NewSkinConsts.FRAME1_WIDTH;
            var _loc_4:* = NewSkinConsts.FRAME1_HEIGHT;
            var _loc_5:* = _loc_3 + LEFT_RIGHT_BETWEEN;
            var _loc_6:* = _loc_1 - _loc_5;
            frame1 = new PhotoFrame();
            frame1.setFrameColorAlpha(NewSkinConsts.FRAME1_FRAMELINE_COLOR, 1);
            frame1.setWidthHeight(_loc_3, _loc_4);
            frame1.x = 0;
            frame1.y = 0;
            addChild(frame1);
            replay = new ReplayBTN();
            replay.x = int((_loc_3 - replay.width) / 2);
            replay.y = int((_loc_4 - replay.height) / 2);
            addChild(replay);
            title = new HrefIconText(NewSkinConsts.SHARE_WIDTH - _loc_5);
            title.textFormat = new TextFormat("宋体", 15, 16777215);
            title.addEventListener(MouseEvent.CLICK, replayHlr);
            title.x = _loc_5;
            title.y = 0;
            addChild(title);
            shareTitle = TextFieldUtil.getTextField();
            shareTitle.defaultTextFormat = new TextFormat("宋体", 13, 10066329, true);
            shareTitle.text = "点击图标转帖到";
            shareTitle.x = _loc_5;
            shareTitle.y = replay.y;
            addChild(shareTitle);
            shareListSprite = RectDisplayUtil.getMaskSprite(_loc_6, 60, 0, 0);
            shareListSprite.x = _loc_5;
            shareListSprite.y = shareTitle.y + shareTitle.height + 10;
            addChild(shareListSprite);
            var _loc_7:* = new HrefIconText(50);
            new HrefIconText(50).textFormat = new TextFormat("宋体", 12, 10066329);
            _loc_7.title = "更多 >>";
            _loc_7.refresh();
            more = _loc_7;
            more.x = _loc_1 - more.width;
            more.y = _loc_2 - more.height;
            addChild(more);
            RectDisplayUtil.drawRect(graphics, _loc_1, _loc_2, 0, 0);
            replay.addEventListener(MouseEvent.CLICK, replayHlr);
            _loc_7.addEventListener(MouseEvent.CLICK, moreClickHlr);
            return;
        }// end function

        private function replayHlr(event:MouseEvent) : void
        {
            dispatchEvent(new SkinEvent(SkinEvent.BUTTON_LOG, SkinButtonCode.REPLAY));
            dispatchEvent(new SkinEvent(SkinEvent.REPLAY));
            return;
        }// end function

        public function setShareItemList(param1:Array) : void
        {
            var _loc_7:IShareItem = null;
            var _loc_8:IconText = null;
            var _loc_9:PictureLoader = null;
            if (param1 == null || param1.length == 0)
            {
                return;
            }
            shareList = [];
            shareListData = param1;
            var _loc_2:Number = 0;
            var _loc_3:Number = 0;
            var _loc_4:* = shareListSprite.width;
            var _loc_5:* = shareListSprite.height;
            var _loc_6:int = 0;
            while (_loc_6 < 8 && _loc_6 < param1.length)
            {
                
                _loc_7 = param1[_loc_6] as IShareItem;
                _loc_8 = new HrefIconText(NewSkinConsts.SHARE_ITEM_WIDTH);
                _loc_9 = new PictureLoader();
                _loc_9.load(_loc_7.iconURL);
                _loc_9.setWidthHeight(NewSkinConsts.SHARE_ICON_LENGTH, NewSkinConsts.SHARE_ICON_LENGTH);
                _loc_9.setBackgroundColorAlpha(0, 0);
                _loc_8.icon = _loc_9;
                _loc_8.title = _loc_7.siteName;
                _loc_8.textFormat = new TextFormat("宋体", 12, 16777215);
                _loc_8.refresh();
                _loc_8.x = _loc_2;
                _loc_8.y = _loc_3;
                shareListSprite.addChild(_loc_8);
                _loc_8.addEventListener(MouseEvent.CLICK, iconTextClick);
                shareList[_loc_6] = _loc_8;
                _loc_6++;
            }
            LayoutUtil.layoutMatrix(shareList, 4, new Rectangle(0, 0, _loc_4, _loc_5));
            return;
        }// end function

        private function iconTextClick(event:MouseEvent) : void
        {
            var _loc_2:* = shareList.indexOf(event.currentTarget);
            var _loc_3:* = shareListData[_loc_2] as IShareItem;
            dispatchEvent(new SkinEvent(SkinEvent.EXIT_FULLSCREEN));
            JSExchanger.getInst().notifyJS("share", [_loc_3.functionName]);
            dispatchEvent(new SkinEvent(SkinEvent.BUTTON_LOG, SkinButtonCode.SHARE + "|" + _loc_2));
            return;
        }// end function

        public function setBaseVideoInfo(param1:IBaseVideoInfo) : void
        {
            baseVideoInfo = param1;
            if (frame1.isLoaded)
            {
                return;
            }
            frame1.load(param1.frame1URL);
            title.title = param1.title;
            title.refresh();
            return;
        }// end function

        private function moreClickHlr(event:MouseEvent) : void
        {
            dispatchEvent(new SkinEvent(SkinEvent.BUTTON_LOG, SkinButtonCode.MORE_SHARE));
            openMoreShare(baseVideoInfo.iid);
            return;
        }// end function

    }
}
